package edu.iss.demo.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import edu.iss.demo.exception.EmloyeeNotFound;

import edu.iss.demo.model.Employee;

import edu.iss.demo.repository.EmployeeRepository;
@Service
public class EmployeeServiceImpl implements EmployeeService
{
	@Resource
	private EmployeeRepository emprep;

	@Override
	@Transactional
	public Employee create(Employee emp)
	{
		Employee enew=emp;
		return emprep.save(enew);
	}

	@Override
	@Transactional
	public Employee findById(String id) {
		// TODO Auto-generated method stub
		return emprep.findOne(id);
		
	}

	@Override
	@Transactional(rollbackFor=EmloyeeNotFound.class)
	public Employee delete(String id) throws EmloyeeNotFound
	{
		Employee edel=emprep.findOne(id);
		if(edel==null)
		{
			return edel;
		}
		else
		{
			emprep.delete(edel);
			return edel;
		}
	}

	@Override
	public List<Employee> findAll()
	{
		
		return emprep.findAll();
	}

//	public Employee update(Employee e) throws EmloyeeNotFound
//	{
//		// TODO Auto-generated method stub
//		return null;
//	}

	@Override
	public Employee update(Employee e) throws EmloyeeNotFound
	{
		Employee eupdate=emprep.findOne(e.getEmployeeId());
		if(eupdate==null)
			return null;
		else
		{
//			eupdate.setName(e.getName());
//			eupdate.setPassword(e.getPassword());
//			eupdate.setDesignation(e.getDesignation());
//			eupdate.setContactNo(e.getContactNo());
//			eupdate.setAddress(e.getAddress());
//			eupdate.setManagerId(e.getManagerId());
//			eupdate.setRole(e.getRole());
//			eupdate.setML_Balance(e.getML_Balance());
//			eupdate.setAL_Balance(e.getAL_Balance());
//			emprep.sa
			emprep.save(e);
			return eupdate;
			
		}
				
		// TODO Auto-generated method stub
	}



	

}
